package ro.cityprojects.adminloc.entities;

import javax.persistence.*;
import java.io.Serializable;

/**
 * PersonAssociationPK class
 *
 * @author bogdan.solga
 * 
 * Date: 13.06.2013, time: 17:47
 */
public class PersonAssociationPK implements Serializable {

    @Id
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "ASSOCIATION_ID", referencedColumnName = "ASSOCIATION_ID", nullable = false)
    private Association associationByAssociationId;

    @Id
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "PERSON_ID", referencedColumnName = "PERSON_ID", nullable = false)
    private Person personByPersonId;

    public Association getAssociationByAssociationId() {
        return associationByAssociationId;
    }

    public void setAssociationByAssociationId(Association associationByAssociationId) {
        this.associationByAssociationId = associationByAssociationId;
    }

    public Person getPersonByPersonId() {
        return personByPersonId;
    }

    public void setPersonByPersonId(Person personByPersonId) {
        this.personByPersonId = personByPersonId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PersonAssociationPK that = (PersonAssociationPK) o;

        if (associationByAssociationId != null ? !associationByAssociationId.equals(that.associationByAssociationId) : that.associationByAssociationId != null)
            return false;
        if (personByPersonId != null ? !personByPersonId.equals(that.personByPersonId) : that.personByPersonId != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = associationByAssociationId != null ? associationByAssociationId.hashCode() : 0;
        result = 31 * result + (personByPersonId != null ? personByPersonId.hashCode() : 0);
        return result;
    }
}
